package com.cyd.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cyd.bean.HomeFeelBean;
import com.cyd.homefamily.R;
import com.cyd.util.ImageLoaderUtil;
import com.paginggv.PagingBaseAdapter;

public class PadingAdapter extends PagingBaseAdapter<HomeFeelBean> {
	private ImageLoaderUtil imageLoader;

	// public PadingAdapter(List<HomeFeelBean> list) {
	// super();
	// this.items = list;
	// }

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return items.size();
	}

	@Override
	public HomeFeelBean getItem(int position) {
		// TODO Auto-generated method stub
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return items.get(position).hashCode();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder = null;
		imageLoader = ImageLoaderUtil.getInstance(parent.getContext());
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(parent.getContext()).inflate(
					R.layout.item_homefeel, null);
			viewHolder.img = (ImageView) convertView.findViewById(R.id.img);
			viewHolder.text = (TextView) convertView
					.findViewById(R.id.textView);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		imageLoader.disPlayImage(getItem(position).getUrl(), viewHolder.img);
		viewHolder.text.setText(getItem(position).getText());
		return convertView;
	}

	private class ViewHolder {
		ImageView img;
		TextView text;
	}

}
